<template>
  <a-spin :spinning="confirmLoading">
    <a-form-model ref="form" :model="model" :rules="validatorRules">
      <a-row :gutter="24">
        <a-col :span="12">
          <a-form-model-item
            :label="$t('销售折扣')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="saleDiscount"
          >
            <a-input-number v-model="model.saleDiscount" :placeholder="$t('请输入销售折扣')" style="width: 95%" /> %
          </a-form-model-item>
          <a-form-model-item
            :label="$t('彩票兑换折扣')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="exLotteryDiscount"
          >
            <a-input-number
              v-model="model.exLotteryDiscount"
              :placeholder="$t('请输入彩票兑换折扣')"
              style="width: 95%"
            />
            %
          </a-form-model-item>
          <a-form-model-item
            :label="$t('积分兑换折扣')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="exIntegralDiscount"
          >
            <a-input-number
              v-model="model.exIntegralDiscount"
              :placeholder="$t('请输入积分兑换折扣')"
              style="width: 95%"
            />
            %
          </a-form-model-item>
        </a-col>
        <a-col :span="12"
          ><a-form-model-item
            :label="$t('币兑换折扣')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="exCoinDiscount"
          >
            <a-input-number
              v-model="model.exCoinDiscount"
              :placeholder="$t('请输入币兑换折扣')"
              style="width: 95%"
            />
            %
          </a-form-model-item>
          <a-form-model-item
            :label="$t('A票兑换折扣')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="exAlotteryDiscount"
          >
            <a-input-number
              v-model="model.exAlotteryDiscount"
              :placeholder="$t('请输入A票兑换折扣')"
              style="width: 95%"
            />
            %
          </a-form-model-item>
          <a-form-model-item
            :label="$t('A币兑换折扣')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="exPointsDiscount"
          >
            <a-input-number
              v-model="model.exPointsDiscount"
              :placeholder="$t('请输入A币兑换折扣')"
              style="width: 95%"
            />
            %
          </a-form-model-item>
        </a-col>
        <a-col :span="24" style="padding-left: 120px;" v-if="!disableSubmit">
          <a-button type="primary" @click="submitForm">{{ $t('保存') }}</a-button>
        </a-col>
      </a-row>
    </a-form-model>
  </a-spin>
</template>

<script>
import { httpAction } from '@/api/manage'

export default {
  name: 'RuleDiscountForm',
  components: {
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data () {
    return {
      disableSubmit: false,
      model:{},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        saleDiscount: [{ required: true, message: this.$t('请输入销售折扣') }],
        exCoinDiscount: [{ required: true, message: this.$t('请输入币兑换折扣') }],
        exLotteryDiscount: [{ required: true, message: this.$t('请输入彩票兑换折扣') }],
        exAlotteryDiscount: [{ required: true, message: this.$t('请输入A票兑换折扣') }],
        exIntegralDiscount: [{ required: true, message: this.$t('请输入积分兑换折扣') }],
        exPointsDiscount: [{ required: true, message: this.$t('请输入A币兑换折扣') }],
      },
      url: {
        add: "/member/bisMemberRule/add",
        edit: "/member/bisMemberRule/edit",
        queryById: "/member/bisMemberRule/queryById"
      }
    }
  },
  created () {
  },
  methods: {
    edit(record) {
      this.visible = true
      this.model = Object.assign({}, record)
    },
    submitForm () {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if(!this.model.id){
            httpurl+=this.url.add;
            method = 'post';
          }else{
            httpurl+=this.url.edit;
             method = 'put';
          }
          httpAction(httpurl,this.model,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }
       
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.cus-form {
  margin-top: 10px;
  margin-left: 40px;
}
</style>